//
//  WordHotTableView.m
//  MyProject
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "WordHotTableView.h"
#import "WordHotTableViewCell.h"

#import "FoodViewController.h"
#import "ActivityViewController.h"
#import "WordHotTableViewModel.h"


@implementation WordHotTableView

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
    
}

- (void)create{
    
    self.tableWordHot = [[UITableView alloc] initWithFrame:self.frame];
    [self addSubview:self.tableWordHot];
    self.tableWordHot.dataSource = self;
    self.tableWordHot.delegate = self;
    self.tableWordHot.rowHeight = self.frame.size.height / 2;
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrayWordHotTabel.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *reuse = @"reuse";
    WordHotTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    
    if (!cell) {
        cell = [[WordHotTableViewCell alloc] init];
    }
    cell.model = self.arrayWordHotTabel[indexPath.row];
    
    
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    // 定义CaTransform3D
    CATransform3D rotation;
    // 设置旋转动画的效果
    // 参数1:角度
    // 参数2:x轴
    // 参数3:y轴
    // 参数4:z轴
    rotation = CATransform3DMakeRotation(750.0 *M_PI/900, 0.0, 0.7, 0.4);
    // m34(透明效果 要操作的这个对想要有旋转的角度  且z方向得有变化才会有透明效果)
    rotation.m34 = 1.0/ - 600;
    cell.layer.shadowColor = [[UIColor blackColor] CGColor];
    // 设置阴影部分的位置
    cell.layer.shadowOffset = CGSizeMake(width *0.02667, width * 0.02667);
    cell.alpha = 0;
    cell.layer.transform = rotation;
    [UIView beginAnimations:@"rotation" context:nil];
    
    [UIView setAnimationDuration:1];
    cell.layer.transform = CATransform3DIdentity;
    // 改变透明度   使动画效果更明显
    cell.alpha = 1;
    // 设置cell的偏移量
    cell.layer.shadowOffset = CGSizeMake(0, 0);
    // 设置动画效果
    [UIView commitAnimations];
    
    return  cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    NSLog(@"%@", self.arrayWordHotTabel);
    WordHotTableViewModel *model = [[WordHotTableViewModel alloc] init];
    model = self.arrayWordHotTabel[indexPath.row];
    if ([model.from[@"name"] isEqualToString: @"餐桌食光"]){
        
        FoodViewController *foodVC = [[FoodViewController alloc] init];
        [self.VC.navigationController pushViewController:foodVC animated:YES];
        foodVC.str = @"http://api.meishi.cc/v5/topic_list2.php?format=jsonlat=&lon=&source=iphone&format=json&gid=20&order=new&page=1&from=0";
       
    }
    
    
    else if ([model.from[@"name"] isEqualToString: @"玩转烘焙"]){
        FoodViewController *foodVC = [[FoodViewController alloc] init];
        [self.VC.navigationController pushViewController:foodVC animated:YES];
        foodVC.str = @"http://api.meishi.cc/v5/topic_list2.php?format=jsonlat=&lon=&source=iphone&format=json&gid=21&order=new&page=1&from=0";
        
    }
    else if([model.from[@"name"] isEqualToString: @"美食课堂"]){
        
        FoodViewController *foodVC = [[FoodViewController alloc] init];
        [self.VC.navigationController pushViewController:foodVC animated:YES];
        foodVC.str = @"http://api.meishi.cc/v5/topic_list2.php?format=jsonlat=&lon=&source=iphone&format=json&gid=22&order=new&page=1&from=0";
        
    }
    else if([model.from[@"name"] isEqualToString: @"最IN活动"]){
        
        ActivityViewController *acVC = [[ActivityViewController alloc] init];
        [self.VC.navigationController pushViewController:acVC animated:YES];
    } else{
        
        NSLog(@"傻不傻"); 
    }

   
}



@end
